function superMachines(machines){
    const totalClothes=machines.reduce((count,val)=>count+val,0)
    const machinesLen=machines.length
    if(totalClothes%machinesLen!==0)
        return -1
    const avgClothes=totalClothes/machinesLen
    let res=0,sum=0
    for (let num of machines) {
        num-=avgClothes
        sum-=num
        res=Math.max(res,Math.abs(sum),num)
    }
    return res
}
machines = [0,0,11,5]

console.log(superMachines(machines));
// 贪心算法